#include "addtaskdialog.h"
#include <QGridLayout>
#include <QLabel>
#include <QUrl>


AddTaskDialog::AddTaskDialog(QWidget *parent) :
    QDialog(parent)
{
    setWindowTitle("Add New Task");

    QGridLayout *gridLayout = new QGridLayout(this);

    gridLayout->addWidget(new QLabel("URL:"), 0, 0);
    gridLayout->addWidget(new QLabel("Rename:"), 1, 0);
    gridLayout->addWidget(new QLabel("Save to:"), 2, 0);
    gridLayout->addWidget(new QLabel("Priority:"), 3, 0);

    urlEdt = new QLineEdit();
    gridLayout->addWidget(urlEdt, 0, 1, 1, 2);

    renameEdt = new QLineEdit();
    gridLayout->addWidget(renameEdt, 1, 1, 1, 2);

    saveToEdt = new QLineEdit("D:\\");
    gridLayout->addWidget(saveToEdt, 2, 1);

    saveToBtn = new QPushButton("Choose..");
    gridLayout->addWidget(saveToBtn, 2, 2);
    connect(saveToBtn, SIGNAL(clicked()), this, SLOT(saveToBtnClicked()));

    priorityBox = new QComboBox(this);
    priorityBox->addItem("low");
    priorityBox->addItem("normal");
    priorityBox->addItem("high");
    gridLayout->addWidget(priorityBox, 3, 1, 1, 2);

    QPushButton *dwnloadBtn = new QPushButton("Download");
    dwnloadBtn->setFocus();
    connect(dwnloadBtn,SIGNAL(clicked()), this, SLOT(accept()));
    gridLayout->addWidget(dwnloadBtn, 4, 1);

    QPushButton *cancelBtn = new QPushButton("Cancel");
    connect(cancelBtn,SIGNAL(clicked()), this, SLOT(reject()));
    gridLayout->addWidget(cancelBtn, 4, 2);

    setLayout(gridLayout);
}

void AddTaskDialog::saveToBtnClicked(){
    QString dir = QFileDialog::getExistingDirectory(this, "Open Directory", "D:\\",
      QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
    saveToEdt->setText(dir);
}

QUrl AddTaskDialog::url(){
    return QUrl::fromUserInput(urlEdt->text());
}

QString AddTaskDialog::rename(){
    return renameEdt->text();
}

QString AddTaskDialog::savePath(){
    return saveToEdt->text();
}

int AddTaskDialog::priority(){
    return priorityBox->currentIndex();
}






